/*
 * 百度在线网络技术（北京）有限公司拥有本软件版权2021并保留所有权利。
 * Copyright 2021, Baidu.com,Inc 2:Baidu Online Network Technology (Beijing) Co.,Ltd,
 * All rights reserved.
 */

package com.azdebugit.spring.beantest.cnblog.spring.valu01;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.Environment;

import com.azdebugit.spring.beantest.cnblog.spring.valu.BeanConfig;
import com.azdebugit.spring.beantest.cnblog.spring.valu.Bottle;

public class TestA {
    @Test
    public void test() {
        //创建容器
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(BeanConfig.class);
        //从容器中获取Bottle实例
        UserService bottle = (UserService) applicationContext.getBean("createUserDao");
        UserService bottle2 = (UserService) applicationContext.getBean("createUserDao");
        UserService bottle3 = (UserService) applicationContext.getBean("createUserDao");
        //控制台输出
        System.out.println(bottle.toString());
        System.out.println(bottle2.toString());
        System.out.println(bottle3.toString());
        //从容器中获取环境变量
//        Environment environment = applicationContext.getEnvironment();
//        String source = environment.getProperty("bottle.source");
//        System.out.println("\n"+source);
        //关闭容器
        ((AnnotationConfigApplicationContext)applicationContext).registerShutdownHook();
    }
}
